package com.example.phonestore.config;

import com.example.phonestore.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;
@Configuration
public class LoginInterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        HandlerInterceptor handlerInterceptor=new LoginInterceptor();

        List<String> patterns=new ArrayList<>();
        patterns.add("/bootstrap3/**");
        patterns.add("/css/**");
        patterns.add("/images/**");
        patterns.add("/js/**");
        patterns.add("/index.html");
        patterns.add("/login.html");
        patterns.add("/product.html");
        patterns.add("/register.html");
        patterns.add("/user/login");
        patterns.add("/user/register");
        patterns.add("/product/showHotProduct");
        patterns.add("/product/{id}/ProductOne");
        patterns.add("/goLogin");
        patterns.add("/goRegister");
        patterns.add("/goIndex");
        patterns.add("/goProductOne");

        registry.addInterceptor(handlerInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(patterns);
    }
}
